/**
 * 销售渠道
 * @author miaoyl
 * @date 2018/01/10
 */
define(function () {

    var self,
        doc = document,
        app = win.app,
        layui = win.layui,
        element,
        table,
        table_param = {},
        cols = [[
            {type:'checkbox',fixed: 'left'},
            {field: 'GWDI001', width: 160, title: '序号', fixed: 'left'}
            , {field: 'GWDI002', width: 160, title: '作业名称'}
            , {field: 'GWDI003', width: 160, title: '单号',search:'default'}
            , {field: 'GWDI004', width: 160, title: '消息日期'}
            , {field: 'GWDI005', width: 300, title: '消息内容'}
            , {field: 'GWDI006', width: 160, title: '消息查看否',filterDatas: app.datas_('crm_gwai880'),search:'default', searchOpts: {type: 'select'}}
            , {field: 'GWDI007', width: 160, title: '消息推送否',filterDatas: app.datas_('crm_gwai880'),search:'default', searchOpts: {type: 'select'}}
            , {field: 'GWDIACTI', width: 160, title: '有效否',filterDatas: app.datas_('sys_y_n')}
            ,{
                width: 60,
                title: '',
                toolbar: '#script-gwai880setting',
                fixed: 'right',
                align: 'center',
                unresize: true
            }
        ]],
        gwai880SettingAction,
        editArea = ['600px', '400px']
    ;

    var Gwai230 = app.Module.extend({
        init: function () {
            self = this;
            self._super({
                _tag: 'gwai880',
                _searchs: [{
                    id: 'gwai880', tableId: 'gwai880_table', datas: cols[0]
                }],
                _loadTplsFull: [{
                    dom: 'gwai880_edit', tpl: 'gwai880_edit'
                }]
            }, win);
        },

        initTable: function () {
            layui.use(['table'], function () {
                table = layui.table;
                table.render({
                    elem: app.getByid(doc, 'gwai880_table'),
                    url: g_ctxPath + 'crm/gwai880/getGwdiList',
                    title: '销售渠道信息表',
                    method: 'post',
                    id: 'gwai880_table',
                    size: _layuiConfig.ui_size,
                    autoSort: false, //禁用前端自动排序
                    toolbar: '#table-toolbar',
                    defaultToolbar: ['filter'],//, 'exports'
                    height: 'full',
                    cols: cols,
                    loading: true,
                    page: true,
                    where: '',
                    done: function (res, curr, count) {

                    }
                });

                layui.laytpl(app.getByid(doc, 'script-gwai880setting-action').innerHTML).render({}, function (string) {
                    gwai880SettingAction = string;
                });

                var tipsIndex = null;

                //监听行双击事件
                table.on('rowDouble(gwai880_table)', function (obj) {
                    self._openTplFull({
                        tag: 'gwai880_edit',
                        tagData: {
                            GWDI001: obj.data.GWDI001
                        },
                        index: 0,
                        openOpts: {
                            title: '我的消息详情',
                            area:editArea
                        }
                    });
                });

                $(doc).on('click', function () {
                    tipsIndex && layer.close(tipsIndex);
                });

            });
        },

        reloadTableCurr: function () {
            self._reloadTable({id: 'gwai880_table', where: table_param});
        },

        delData: function (obj) {
            app.confirm({
                msg: '是否删除选择的信息？',
                ok: function () {
                    app.ajax({
                        xurl: 'crm/gwai880/del',
                        xdata: obj.data,
                        loading: true,
                        okmsg: '销售渠道删除成功',
                        cb: function (result) {
                            if (result.ok) {
                                self.reloadTableCurr();
                            }
                        }
                    });
                }
            });

        },

        delDataBatch: function(){
            var checkStatus = table.checkStatus('gwai880_table');
            if (checkStatus.data.length > 0) {
                var _xdata = [];
                checkStatus.data.forEach(function (v) {
                    var _temp = app.fields_('crm_gwai880');
                    _temp.GWAE001 = v.GWAE001;
                    _temp.GWAEL001 = v.GWAEL001;
                    _xdata.push(_temp);
                });
                app.ajax({
                    xurl: 'crm/gwai880/delDataBatch',
                    xdata: _xdata,
                    loading: true,
                    toJsonStr: true,
                    okmsg: '销售渠道信息删除成功',
                    cb: function (result) {
                        if (result.ok) {
                            self.reloadTableCurr();
                        }
                    }
                });
            }
        },

        _ready: function () {
            this._super({
                vue: [{
                    el: '#page',
                    data: '',
                    searchId: 'gwai880',
                    methods: {}
                }]
            });
            self.initTable();
        },
        _lazy: function () {
            this._super();
            layui.use(['table'], function () {
                element = layui.element;
            });
        }
    });

    return new Gwai230();

});